﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DMS.Business.Modules.Organization;
using DMS.Business.Modules.SupplierManagement;
using DMS.Business.Utility;
using DMS.BaseClass;

namespace DMS.Web.Modules.SupplierManagement
{
    public partial class ResetPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
                if (Request["id"] != "")
                {
                    User account = UserHelper.GetUserByID(Request["id"]);
                    if(account!=null)
                        this.UserName.InnerText = "正在为【"+account.Name+"】重置密码：";
                }

            if(!IsPostBack)
            {
                this.user_id.Value = Request["id"];
            }
                    

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            try
            {
                //SupplierAccount account;
                User account;
                if (this.user_id.Value != "")
                    account = UserHelper.GetUserByID(Request["id"]);
                else
                    account = SystemContext.Current.LoginUser;
//                User account = SystemContext.Current.LoginUser;
                account.ResetPassword(txtPassword.Text);

                ClientHelper.Instance.CloseWindow("保存成功", "ok", RefreshType.OpenDialog);
            }
            catch (Exception ex)
            {
                string code = LogHelper.LogException(ex);
                string msg = string.Format("操作失败，请联系管理员。\\r\\n错误码：{0}", code);
                ClientHelper.Instance.Alert(msg);
            }
        }
    }
}